#include <iostream>
#include <cstring>
#include "../include/HowMany.h"
#include "../include/HowMany2.h"
#include "../include/WitchCC.h"
#include "../include/Integer.h"
#include "../include/Tree.h"
#include "../include/Instrument.h"
#include "../include/Pet.h"
#include "../src_template/Array.h"
#include "../exception/Trace.h"
#include "../exception/Cat.h"
#include "../src_string/exercise_str.h"

int main() {
	HowMany h;
	HowMany::print("after construction of h");

	HowMany h2 = f(h);

	h2.print("=========");

	// 按值传递 返回对象地址不同  析构函数执行3次
	printf("h address is %p  h1 address is %p \n", &h, &h2);

	cout << ("====================================") << endl;


	HowMany2 many1;
	HowMany2 many2 = f(many1);
	many2.print("H2 after call to f()");

	HowMany2 manyStr = HowMany2("abcx");

	printf("h address is %p  h1 address is %p \n", &many1, &many2);

	cout << ("====================================") << endl;

	HowMany2 m23 = HowMany2("abcedef");

	cout << ("====================================") << endl;

	WitchCC cc;
	cout << ("====================================") << endl;

	const_print();
	cout << ("====================================") << endl;

	int i = 1, j = 2, k = 3;
	k += i + j;
	cout << " user-defined types:" << endl;
	cout << "k：" << k << endl;

	Integer ii(i), jj(2), kk(3);
	
	kk += ii + jj;
	
	cout << kk.getValue() << endl;

	cout << ("====================================") << endl;

	char* str = (char*) ::malloc(15);

	strcpy(str, "runoob");
	::printf("String = %s , address = %u\n", str, str);

	cout << ("====================================") << endl;
	Tree* t = new Tree(40);
	cout << t;
	// 返回对象指针
	Tree t123 = *new Tree(2);
	delete t;

	cout << ("====================================") << endl;

	Instrument ins = *new Instrument();
	ins.play(Csharp);

	Wind wind = *new Wind();
	wind.play(Cflat);

	// 调用父类方法
	Instrument parent = *new Wind();
	parent.play(middleC);

	// 编译异常
	// Wind child = *new Instrument();
	Instrument* ins_prt = new Instrument();
	ins_prt->play(Csharp);

	Wind* wind_prt = new Wind();
	wind_prt->play(Cflat);

	// 调用子类方法(多态）
	Instrument* parent_prt = new Wind();
	parent_prt->play(middleC);


	Pet* pet = new Pet("miamiaole");

	Pet* sub = new Dog("12212");

	cout << pet->name() << endl;
	cout << sub->name() << endl;

	cout << ("====================================") << endl;


	Pet1::Pet p("alfred");

	Pet1::Dog d1("Fluffy", "sleep");

	cout << ("=============Array==================") << endl;

	Array<int> ia;
	Array<float> fa;

	for (int i = 0; i < 20; ++i) {
		ia[i] = i * i;
		fa[i] = float(i) * 1.313;
	}

	for (int i = 0; i < 20; ++i) {
		cout << i << ":" << ia[i] << "\n" <<
			"，" << fa[j] << endl;
	}

	operation_str();

	try {
		Trace n1;
		Trace n2;
		Trace n3;
		Trace n4;
	}
	catch (int a) {
		cout << a << endl;
	}

	try {
		UseResource ur(3);
	}
	catch (int a) {
		cout << a << endl;
	}


}

